#$ARGV[0] is the occupiedRatio file.
#$ARGV[1] is the length Of Series.

$file = $ARGV[0];
$lengthOfSeries = 1000;
if($ARGV[1]!=0){
	$lengthOfSeries = $ARGV[1];
}

@pathname = split(/\\/,$file);
$len = @pathname;
$path;
print "$len\n";
for($i=$len-2;$i>=0;$i--){
	$path = "$pathname[$i]\\"."$path";
	print "$path\n";
}

$numOfSeries = 16;

@occRatio;
$m=0;
open fin, "<$file" or die "can not open file $file!\n";
while (<fin>) {
	chomp;
	@info = split;

	$occRatio[$m]=$info[2];
	print "$occRatio[$m]\n";
	$m++;
}
close fin;

@sample;
for($i=0;$i<$lengthOfSeries;$i++){
	for($j=0;$j<$numOfSeries;$j++){
		$sample[$j][$i]=0;
	}
}

for($j=0;$j<$numOfSeries;$j++){
	for($i=0;$i<$lengthOfSeries;$i++){
		$temprand=rand();
		#print "$temprand\n";
		if($temprand<=$occRatio[$j]){
			$sample[$j][$i]=1;
		}
		else{
			$sample[$j][$i]=0;
		}
	}
}

$fileName="random01Series.dat";
open fout, ">$path\\$fileName" or die "can not open file $path\\$fileName\n";
for($i=0;$i<$lengthOfSeries+1;$i++){
	for($j=0;$j<$numOfSeries;$j++){
		print fout "$sample[$j][$i] ";
	}
	print fout "\n";
}
close fout;

